<?php

/**
 * model_appoint
 * 职位
 */

class Model_appoint extends YOU {

	public function __construct()
	{
		parent::__construct();
	}

	/** 学生职位名称信息 **/
	public function getInfo($leader_name, $field = "*")
	{
		$data = $this->db->fetchRow("SELECT {$field} FROM `tbl_student_leader` WHERE leader_name='{$leader_name}' ");

		return $data;
	}
	
	/** 学生职位全部信息 **/
	public function getAll($field = "*")
	{
		$data = $this->db->fetchAll("SELECT {$field} FROM `tbl_student_leader` ");

		return $data;
	}
	/** 学生职位名称信息 **/
	public function getRow($leader_id, $field = "*")
	{
		$data = $this->db->fetchRow("SELECT {$field} FROM `tbl_student_leader` WHERE leader_id='{$leader_id}' ");
	
		return $data;
	}
	/** 老师职位任职信息(所有) **/
	public function getStaffinfo($field = "*")
	{	
		$appoint_lists = $this->db->fetchAll("SELECT {$field} FROM `tbl_appoint`");
		
		return $appoint_lists;
	}
	/** 取出所有部门普通员工 **/
	public function getDsel($department_id, $field = "*")
	{	
		$appoint_lists = $this->db->fetchAll("SELECT {$field} FROM `tbl_appoint` WHERE department_id='{$department_id}' AND appoint_common='1'");
		
		return $appoint_lists;
	}
	/** 取出所有教研组普通员工 **/
	public function getResearch($research_id, $field = "*")
	{	
		$appoint_lists = $this->db->fetchAll("SELECT {$field} FROM `tbl_appoint` WHERE research_id='{$research_id}' AND appoint_common='1'");
		
		return $appoint_lists;
	}
	/** 取出所有备课组普通员工 **/
	public function getPrepare($prepare_id, $field = "*")
	{	
		$appoint_lists = $this->db->fetchAll("SELECT {$field} FROM `tbl_appoint` WHERE prepare_id='{$prepare_id}' AND appoint_common='1'");
		
		return $appoint_lists;
	}
	/** 取出所有学科组普通员工 **/
	public function getDisc($discipline_id, $field = "*")
	{	
		$appoint_lists = $this->db->fetchAll("SELECT {$field} FROM `tbl_appoint` WHERE discipline_id='{$discipline_id}' AND appoint_common='1'");
		
		return $appoint_lists;
	}
	/** 部门-通过老师id、部门id(一条) **/
	public function getDselRow($staff_id, $department_id, $field = "*")
	{	
		$appoint_data = $this->db->fetchRow("SELECT {$field} FROM `tbl_appoint` WHERE department_id='{$department_id}'AND staff_id='{$staff_id}' AND appoint_common='1'");
		
		return $appoint_data;
	}
	/** 教研组-通过老师id、教研组id(一条) **/
	public function getResRow($staff_id, $research_id, $field = "*")
	{	
		$appoint_data = $this->db->fetchRow("SELECT {$field} FROM `tbl_appoint` WHERE research_id='{$research_id}'AND staff_id='{$staff_id}' AND appoint_common='1'");
		
		return $appoint_data;
	}
	/** 备课组-通过老师id、部门id(一条) **/
	public function getPreRow($staff_id, $prepare_id, $field = "*")
	{	
		$appoint_data = $this->db->fetchRow("SELECT {$field} FROM `tbl_appoint` WHERE prepare_id='{$prepare_id}'AND staff_id='{$staff_id}' AND appoint_common='1'");
		
		return $appoint_data;
	}
	/** 学科组-通过老师id、部门id(一条) **/
	public function getDiscRow($staff_id, $discipline_id, $field = "*")
	{	
		$appoint_data = $this->db->fetchRow("SELECT {$field} FROM `tbl_appoint` WHERE discipline_id='{$discipline_id}'AND staff_id='{$staff_id}' AND appoint_common='1'");
		
		return $appoint_data;
	}
	/** 老师职位任职信息(所有不重复) **/
	public function getStaffAll()
	{	
		
		$appoint_lists = $this->db->fetchAll("SELECT distinct staff_id FROM `tbl_appoint` order by staff_id");
		
		foreach($appoint_lists as $key => $value){
			if($value['class_id'] != 0){
				unset($appoint_lists[$key]);
				
			}
			
		}
		
		return $appoint_lists;
	}
	/** 老师职位任职信息(所有) **/
	public function getStaffType($type_id, $field = "*")
	{	
		
		$appoint_lists = $this->db->fetchAll("SELECT {$field} FROM `tbl_appoint` WHERE staff_id='{$type_id}'");
		
		return $appoint_lists;
	}
	/** 老师职位信息部门(参数 部门id) **/
	public function getSinfo($department_id, $field = "*")
	{	
		$data = $this->db->fetchRow("SELECT {$field} FROM `tbl_appoint` WHERE department_id='{$department_id}' ");
		
		return $data;
	}

	/** 老师职位信息部门所有的 **/
	public function getSAll($field = "*")
	{	
		$data = $this->db->fetchAll("SELECT {$field} FROM `tbl_appoint` WHERE department_id!='0'");
		
		return $data;
	}
	/** 老师职位信息部门(参数 教研组id)单条 **/
	public function getRinfo($research_id, $field = "*")
	{	
		$data = $this->db->fetchRow("SELECT {$field} FROM `tbl_appoint` WHERE research_id='{$research_id}' ");
	
		return $data;
	}

	/** 老师职位信息教研组所有的 **/
	public function getRAll($field = "*")
	{	
		$data = $this->db->fetchAll("SELECT {$field} FROM `tbl_appoint` WHERE research_id!='0'");
		
		return $data;
	}
	/** 老师职位信息部门(参数 备课组id) **/
	public function getPinfo($prepare_id, $field = "*")
	{	
		$data = $this->db->fetchRow("SELECT {$field} FROM `tbl_appoint` WHERE prepare_id='{$prepare_id}' ");
		
		return $data;
	}
	/** 老师职位信息备课组所有的 **/
	public function getPAll($field = "*")
	{	
		$data = $this->db->fetchAll("SELECT {$field} FROM `tbl_appoint` WHERE prepare_id!='0'");
		
		return $data;
	}
	/** 老师职位信息部门(参数 学科组id) **/
	public function getDinfo($discipline_id, $field = "*")
	{	
		$data = $this->db->fetchRow("SELECT {$field} FROM `tbl_appoint` WHERE discipline_id='{$discipline_id}' ");
		
		return $data;
	}
	/** 老师职位信息学科组所有的 **/
	public function getDAll($field = "*")
	{	
		$data = $this->db->fetchAll("SELECT {$field} FROM `tbl_appoint` WHERE discipline_id!='0'");
		
		return $data;
	}
	
	/** 取得教师职务信息 **/
	public function getPositionByStaff($staff_id)
	{
		$data_lists = $this->db->fetchAll("SELECT * FROM `tbl_appoint` WHERE staff_id='{$staff_id}' ");
		$this->position_type = array(
		"0" => "班主任",
		"1" => "级长",
		"2" => "副级长",
		"3" => "组长",
		"4" => "副组长",
		);
		foreach ($data_lists as $key=>$value){
			// 部门
			if ($value['appoint_type'] == 1) {
				$row = $this->db->fetchrow("SELECT * FROM `tbl_position` WHERE position_id='{$value['position_id']}' ");
				$data[] = $row['position_name'];
			
			}
			if ($value['appoint_type'] == 2) {
				$data[] = '教研组'.$this->position_type[$value['position_type']];
				
			}
			// 级长
			if ($value['appoint_type'] == 3){
				
				$data[]  = $this->position_type[$value['position_type']];
			
			}
			if ($value['appoint_type'] == 4){
				
				$data[] = $this->position_type[$value['position_type']];
				
			}
			if ($value['appoint_type'] == 5){
				
				$data[] = '备课组'.$this->position_type[$value['position_type']];
				
			}
			// 学科组
			if ($value['appoint_type'] == 6){
				
				$data[] = '学科组'.$this->position_type[$value['position_type']];
				
			}
		}
		
		return $data;
	}
	/** 取得班主任所有老师 **/
	public function getTeacherAll($field = "*")
	{
		$data_lists = $this->db->fetchAll("SELECT {$field} FROM `tbl_appoint`  WHERE appoint_type='4' AND position_type='0' ");

		return $data_lists;
	}
	/** 通过staff_id 查看是否是任职老师 **/
	public function getTeacherRow($staff_id, $field = "*")
	{
		$data_lists = $this->db->fetchRow("SELECT {$field} FROM `tbl_appoint`  WHERE staff_id = '{$staff_id}' ");

		return $data_lists;
	}

}



?>